package com.szt.mobiles.inventory.common.entity;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "t_assets".
*/
public class AssetsDao extends AbstractDao<Assets, Long> {

    public static final String TABLENAME = "t_assets";

    /**
     * Properties of entity Assets.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property _id = new Property(0, Long.class, "_id", true, "_id");
        public final static Property ASSET_ID = new Property(1, String.class, "ASSET_ID", false, "ASSET__ID");
        public final static Property AUTOID = new Property(2, String.class, "aUTOID", false, "A_UTOID");
        public final static Property Asset70 = new Property(3, String.class, "asset70", false, "ASSET70");
        public final static Property Asset90 = new Property(4, String.class, "asset90", false, "ASSET90");
        public final static Property Strasset150 = new Property(5, String.class, "strasset150", false, "STRASSET150");
        public final static Property Strasset250 = new Property(6, String.class, "strasset250", false, "STRASSET250");
        public final static Property Asset700 = new Property(7, String.class, "asset700", false, "ASSET700");
        public final static Property Asset240 = new Property(8, String.class, "asset240", false, "ASSET240");
        public final static Property Asset250 = new Property(9, String.class, "asset250", false, "ASSET250");
        public final static Property RESULT_TYPE = new Property(10, String.class, "RESULT_TYPE", false, "RESULT__TYPE");
        public final static Property Status = new Property(11, Integer.class, "status", false, "STATUS");
        public final static Property AssetsListId = new Property(12, Long.class, "assetsListId", false, "ASSETS_LIST_ID");
    }

    private Query<Assets> assetsList_AssetQuery;

    public AssetsDao(DaoConfig config) {
        super(config);
    }
    
    public AssetsDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"t_assets\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: _id
                "\"ASSET__ID\" TEXT," + // 1: ASSET_ID
                "\"A_UTOID\" TEXT," + // 2: aUTOID
                "\"ASSET70\" TEXT," + // 3: asset70
                "\"ASSET90\" TEXT," + // 4: asset90
                "\"STRASSET150\" TEXT," + // 5: strasset150
                "\"STRASSET250\" TEXT," + // 6: strasset250
                "\"ASSET700\" TEXT," + // 7: asset700
                "\"ASSET240\" TEXT," + // 8: asset240
                "\"ASSET250\" TEXT," + // 9: asset250
                "\"RESULT__TYPE\" TEXT," + // 10: RESULT_TYPE
                "\"STATUS\" INTEGER," + // 11: status
                "\"ASSETS_LIST_ID\" INTEGER);"); // 12: assetsListId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"t_assets\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, Assets entity) {
        stmt.clearBindings();
 
        Long _id = entity.get_id();
        if (_id != null) {
            stmt.bindLong(1, _id);
        }
 
        String ASSET_ID = entity.getASSET_ID();
        if (ASSET_ID != null) {
            stmt.bindString(2, ASSET_ID);
        }
 
        String aUTOID = entity.getAUTOID();
        if (aUTOID != null) {
            stmt.bindString(3, aUTOID);
        }
 
        String asset70 = entity.getAsset70();
        if (asset70 != null) {
            stmt.bindString(4, asset70);
        }
 
        String asset90 = entity.getAsset90();
        if (asset90 != null) {
            stmt.bindString(5, asset90);
        }
 
        String strasset150 = entity.getStrasset150();
        if (strasset150 != null) {
            stmt.bindString(6, strasset150);
        }
 
        String strasset250 = entity.getStrasset250();
        if (strasset250 != null) {
            stmt.bindString(7, strasset250);
        }
 
        String asset700 = entity.getAsset700();
        if (asset700 != null) {
            stmt.bindString(8, asset700);
        }
 
        String asset240 = entity.getAsset240();
        if (asset240 != null) {
            stmt.bindString(9, asset240);
        }
 
        String asset250 = entity.getAsset250();
        if (asset250 != null) {
            stmt.bindString(10, asset250);
        }
 
        String RESULT_TYPE = entity.getRESULT_TYPE();
        if (RESULT_TYPE != null) {
            stmt.bindString(11, RESULT_TYPE);
        }
 
        Integer status = entity.getStatus();
        if (status != null) {
            stmt.bindLong(12, status);
        }
 
        Long assetsListId = entity.getAssetsListId();
        if (assetsListId != null) {
            stmt.bindLong(13, assetsListId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Assets entity) {
        stmt.clearBindings();
 
        Long _id = entity.get_id();
        if (_id != null) {
            stmt.bindLong(1, _id);
        }
 
        String ASSET_ID = entity.getASSET_ID();
        if (ASSET_ID != null) {
            stmt.bindString(2, ASSET_ID);
        }
 
        String aUTOID = entity.getAUTOID();
        if (aUTOID != null) {
            stmt.bindString(3, aUTOID);
        }
 
        String asset70 = entity.getAsset70();
        if (asset70 != null) {
            stmt.bindString(4, asset70);
        }
 
        String asset90 = entity.getAsset90();
        if (asset90 != null) {
            stmt.bindString(5, asset90);
        }
 
        String strasset150 = entity.getStrasset150();
        if (strasset150 != null) {
            stmt.bindString(6, strasset150);
        }
 
        String strasset250 = entity.getStrasset250();
        if (strasset250 != null) {
            stmt.bindString(7, strasset250);
        }
 
        String asset700 = entity.getAsset700();
        if (asset700 != null) {
            stmt.bindString(8, asset700);
        }
 
        String asset240 = entity.getAsset240();
        if (asset240 != null) {
            stmt.bindString(9, asset240);
        }
 
        String asset250 = entity.getAsset250();
        if (asset250 != null) {
            stmt.bindString(10, asset250);
        }
 
        String RESULT_TYPE = entity.getRESULT_TYPE();
        if (RESULT_TYPE != null) {
            stmt.bindString(11, RESULT_TYPE);
        }
 
        Integer status = entity.getStatus();
        if (status != null) {
            stmt.bindLong(12, status);
        }
 
        Long assetsListId = entity.getAssetsListId();
        if (assetsListId != null) {
            stmt.bindLong(13, assetsListId);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public Assets readEntity(Cursor cursor, int offset) {
        Assets entity = new Assets( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // _id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // ASSET_ID
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // aUTOID
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // asset70
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // asset90
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // strasset150
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // strasset250
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // asset700
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // asset240
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // asset250
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // RESULT_TYPE
            cursor.isNull(offset + 11) ? null : cursor.getInt(offset + 11), // status
            cursor.isNull(offset + 12) ? null : cursor.getLong(offset + 12) // assetsListId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Assets entity, int offset) {
        entity.set_id(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setASSET_ID(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setAUTOID(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setAsset70(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setAsset90(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setStrasset150(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setStrasset250(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setAsset700(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setAsset240(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setAsset250(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setRESULT_TYPE(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setStatus(cursor.isNull(offset + 11) ? null : cursor.getInt(offset + 11));
        entity.setAssetsListId(cursor.isNull(offset + 12) ? null : cursor.getLong(offset + 12));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Assets entity, long rowId) {
        entity.set_id(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Assets entity) {
        if(entity != null) {
            return entity.get_id();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(Assets entity) {
        return entity.get_id() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "asset" to-many relationship of AssetsList. */
    public List<Assets> _queryAssetsList_Asset(Long assetsListId) {
        synchronized (this) {
            if (assetsList_AssetQuery == null) {
                QueryBuilder<Assets> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.AssetsListId.eq(null));
                assetsList_AssetQuery = queryBuilder.build();
            }
        }
        Query<Assets> query = assetsList_AssetQuery.forCurrentThread();
        query.setParameter(0, assetsListId);
        return query.list();
    }

}
